from exts import db
from datetime import datetime


class Account(db.Model):
    __tablename__ = 'account'
    id = db.Column(db.Integer, primary_key=True, autoincrement=True)
    username = db.Column(db.String(100), nullable=False)
    password = db.Column(db.String(200), nullable=False)
    email = db.Column(db.String(100), nullable=False, unique=True)
    ctime = db.Column(db.DateTime, default=datetime.now)
    dept = db.relationship("Dept", back_populates="manage")


class Dept(db.Model):
    __tablename__ = 'dept'
    id = db.Column(db.Integer, primary_key=True, autoincrement=True)
    name = db.Column(db.String(100), nullable=False)
    # 主外键关系
    manager_id = db.Column(db.Integer, db.ForeignKey('account.id'))
    manager = db.relationship(Account, backref="dept_id")
    # 主外键关系二
    # manage = db.relationship("Account", back_populates="dept")
